unit Class_Plac;

interface
uses
  Classes,SysUtils,ADODB,DBEngine;

type
  TPlac=class(TDBEngine)
  public
    UnitLink: string;
    PlacIdex: string;
    PlacPrev: string;
    PlacCode: string;
    PlacName: string;
    PlacLink: string;
    PlacLevl: integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
    class function ReadDS(AADODS:TADODataSet):TDBEngine;override;    
  end;


implementation

{ TPlac }

function TPlac.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_PLAC WHERE UNIT_LINK=:UNIT_LINK AND PLAC_IDEX=:PLAC_IDEX';
end;

function TPlac.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_PLAC ' 
        + '    (UNIT_LINK, PLAC_IDEX, PLAC_PREV, PLAC_CODE, PLAC_NAME, PLAC_LINK, PLAC_LEVL)'
        + '    VALUES(:UNIT_LINK, :PLAC_IDEX, :PLAC_PREV, :PLAC_CODE, :PLAC_NAME, :PLAC_LINK, :PLAC_LEVL)';
end;

function TPlac.GetStrUpdate: string;
begin
  Result:='UPDATE TBL_PLAC SET'
        + '    UNIT_LINK = :UNIT_LINK,'
        + '    PLAC_IDEX = :PLAC_IDEX,'
        + '    PLAC_PREV = :PLAC_PREV,'
        + '    PLAC_CODE = :PLAC_CODE,'
        + '    PLAC_NAME = :PLAC_NAME'
        + '    WHERE  PLAC_LINK = :PLAC_LINK,'
        + '    AND    PLAC_LEVL = :PLAC_LEVL';
end;

class function TPlac.ReadDS(AADODS: TADODataSet): TDBEngine;
begin
  Result:=TPlac.Create;
  with TPlac(Result) do
  begin
    UNITLINK := Trim(AADODS.FieldByName('UNIT_LINK').AsString);
    PLACIDEX := Trim(AADODS.FieldByName('PLAC_IDEX').AsString);
    PLACPREV := Trim(AADODS.FieldByName('PLAC_PREV').AsString);
    PLACCODE := Trim(AADODS.FieldByName('PLAC_CODE').AsString);
    PLACNAME := Trim(AADODS.FieldByName('PLAC_NAME').AsString);
    PLACLINK := Trim(AADODS.FieldByName('PLAC_LINK').AsString);
    PLACLEVL := AADODS.FieldByName('PLAC_LEVL').AsInteger;
  end;
end;

procedure TPlac.SetParameters;
begin
  inherited;
  with FADOCmd.Parameters do
  begin
    ParamByName('UNIT_LINK').Value := UNITLINK;
    ParamByName('PLAC_IDEX').Value := PLACIDEX;
    ParamByName('PLAC_PREV').Value := PLACPREV;
    ParamByName('PLAC_CODE').Value := PLACCODE;
    ParamByName('PLAC_NAME').Value := PLACNAME;
    ParamByName('PLAC_LINK').Value := PLACLINK;
    ParamByName('PLAC_LEVL').Value := PLACLEVL;
  end;
end;

end.
